Load balancing enabled in places where it's thought to be reasonably safe
[lhc/web/wiklou.git] / includes / SpecialAllpages.php
1 <?php
2
3 function wfSpecialAllpages( $par=NULL )
4 {
5 global $indexMaxperpage, $wgRequest, $wgLoadBalancer;
6 $indexMaxperpage = 480;
7 $from = $wgRequest->getVal( 'from' );
8
9 $wgLoadBalancer->force(-1);
10
11 if( $par ) {
12 indexShowChunk( $par );
13 } elseif( !is_null( $from ) ) {
14 indexShowChunk( $from );
15 } else {
16 indexShowToplevel();
17 }
18
19 $wgLoadBalancer->force(0);
20 }
21
22 function indexShowToplevel()
23 {
24 global $wgOut, $indexMaxperpage, $wgLang;
25 $fname = "indexShowToplevel";
26
27 # Cache
28 $vsp = $wgLang->getValidSpecialPages();
29 $log = new LogPage( $vsp["Allpages"] );
30 $log->mUpdateRecentChanges = false;
31
32 global $wgMiserMode;
33 if ( $wgMiserMode ) {
34 $log->showAsDisabledPage();
35 return;
36 }
37
38 $fromwhere = "FROM cur WHERE cur_namespace=0";
39 $order = "ORDER BY cur_title";
40 $out = "";
41
42 $sql = "SELECT COUNT(*) AS count $fromwhere";
43 $res = wfQuery( $sql, DB_READ, $fname );
44 $s = wfFetchObject( $res );
45 $count = $s->count;
46 $sections = ceil( $count / $indexMaxperpage );
47
48 $sql = "SELECT cur_title $fromwhere $order LIMIT 1";
49 $res = wfQuery( $sql, DB_READ, $fname );
50 $s = wfFetchObject( $res );
51 $inpoint = $s->cur_title;
52
53 $out .= "<table>\n";
54 # There's got to be a cleaner way to do this!
55 for( $i = 1; $i < $sections; $i++ ) {
56 $from = $i * $indexMaxperpage;
57 $sql = "SELECT cur_title $fromwhere $order ".wfLimitResult(2,$from);
58 $res = wfQuery( $sql, DB_READ, $fname );
59
60 $s = wfFetchObject( $res );
61 $outpoint = $s->cur_title;
62 $out .= indexShowline( $inpoint, $outpoint );
63
64 $s = wfFetchObject( $res );
65 $inpoint = $s->cur_title;
66
67 wfFreeResult( $res );
68 }
69
70 $from = $i * $indexMaxperpage;
71 $sql = "SELECT cur_title $fromwhere $order ".wfLimitResult(1,$count-1);
72 $res = wfQuery( $sql, DB_READ, $fname );
73 $s = wfFetchObject( $res );
74 $outpoint = $s->cur_title;
75 $out .= indexShowline( $inpoint, $outpoint );
76 $out .= "</table>\n";
77
78 # Saving cache
79 $log->replaceContent( $out );
80
81 $wgOut->addHtml( $out );
82 }
83
84 function indexShowline( $inpoint, $outpoint )
85 {
86 global $wgOut, $wgLang, $wgUser;
87 $sk = $wgUser->getSkin();
88
89 # Fixme: this is ugly
90 $out = wfMsg(
91 "alphaindexline",
92 $sk->makeKnownLink( $wgLang->specialPage( "Allpages" ),
93 str_replace( "_", " ", $inpoint ),
94 "from=" . wfStrencode( $inpoint ) ) . "</td><td>",
95 "</td><td align=\"left\">" .
96 str_replace( "_", " ", $outpoint )
97 );
98 return "<tr><td align=\"right\">{$out}</td></tr>\n";
99 }
100
101 function indexShowChunk( $from )
102 {
103 global $wgOut, $wgUser, $indexMaxperpage, $wgLang;
104 $sk = $wgUser->getSkin();
105 $maxPlusOne = $indexMaxperpage + 1;
106
107 $out = "";
108 $sql = "SELECT cur_title FROM cur WHERE cur_namespace=0 AND cur_title >= '"
109 . wfStrencode( $from ) . "' ORDER BY cur_title LIMIT " . $maxPlusOne;
110 $res = wfQuery( $sql, DB_READ, "indexShowChunk" );
111
112 ### FIXME: side link to previous
113
114 $n = 0;
115 $out = "<table border=\"0\" width=\"100%\">\n";
116 while( ($n < $indexMaxperpage) && ($s = wfFetchObject( $res )) ) {
117 $t = Title::makeTitle( 0, $s->cur_title );
118 if( $t ) {
119 $link = $sk->makeKnownLinkObj( $t );
120 } else {
121 $link = "[[" . htmlspecialchars( $s->cur_title ) . "]]";
122 }
123 if( $n % 3 == 0 ) {
124 $out .= "<tr>\n";
125 }
126 $out .= "<td>$link</td>";
127 $n++;
128 if( $n % 3 == 0 ) {
129 $out .= "</tr>\n";
130 }
131 }
132 if( ($n % 3) != 0 ) {
133 $out .= "</tr>\n";
134 }
135 $out .= "</table>";
136
137 $out2 = "<div style='text-align: right; font-size: smaller; margin-bottom: 1em;'>" .
138 $sk->makeKnownLink( $wgLang->specialPage( "Allpages" ),
139 wfMsg ( 'allpages' ) );
140 if ( ($n == $indexMaxperpage) && ($s = wfFetchObject( $res )) ) {
141 $out2 .= " | " . $sk->makeKnownLink(
142 $wgLang->specialPage( "Allpages" ),
143 wfMsg ( 'nextpage', $s->cur_title ),
144 "from=" . wfStrencode( $s->cur_title ) );
145 }
146 $out2 .= "</div>";
147
148 $wgOut->addHtml( $out2 . $out );
149 }
150
151 ?>